package com.m2bshop.shop.controller;

import com.m2bshop.shop.dao.JMFgoodsDao;
import com.m2bshop.shop.pojo.BMCgoods;
import com.m2bshop.shop.pojo.JMFgoods;
import com.m2bshop.shop.pojo.Result.Result;

import com.m2bshop.shop.service.JMFgoodsService;
import com.m2bshop.shop.service.JmfOrderService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author asus
 * @create 2022/6/12 15:11
 */
@Controller
@RequestMapping("/JMF")
public class JMFgoodsController {

    @Autowired
    private JMFgoodsService jmFgoodsService;
    @Autowired
    private JmfOrderService jmfOrderService;
    //跳转到商品页面
    @RequestMapping("/list")
    public String list() {
        return "JMF/JMFgoodList";
    }

    @RequestMapping("/add")
    @ResponseBody
    public Result addgoods(HttpSession session, @Param("id") int id){
        System.out.println(id);
        Integer userid = Integer.parseInt(session.getAttribute("userId")+"");
        int i = jmFgoodsService.add(id,userid);
        System.out.print(i);
//        return Result.ok(favoritesList);
        return Result.ok();
    }
    /*@RequestMapping("/update")
    public Result updategoods(){
        return Result.ok();
    }

    @RequestMapping("/delete")
    public Result deletegoods(){
        return Result.ok();
    }
*/
    @RequestMapping("/queryAll")
    @ResponseBody
    public Result queryAllgoods(){
        List<JMFgoods> jmFgoods = jmFgoodsService.queryAll();
        System.out.print(jmFgoods);
        return Result.ok(jmFgoods);
    }

    /*@RequestMapping("/queryById")
    public Result queryByIdgoods(){
        return Result.ok();
    }*/
    @RequestMapping("/add1")
    @ResponseBody
    public Result addgoodsa(HttpSession session, @Param("id") int id){
        System.out.println(id);
        Integer userid = Integer.parseInt(session.getAttribute("userId")+"");
        /*Integer gid =Integer.parseInt(session.getAttribute("gid")+"");*/
        int i = jmFgoodsService.add1(id,userid);
        int j =jmFgoodsService.seleo(id);
        jmfOrderService.createorder(j);
        System.out.print(i);
        System.out.print(j);
        /*System.out.print(gid);*/
//        return Result.ok(favoritesList);
        return Result.ok();
    }

}
